package com.lagou.sqlsession;

import com.lagou.config.XMLConfigBuild;
import com.lagou.pojo.Configuration;
import org.dom4j.DocumentException;

import java.io.InputStream;

public class SqlSessionFactoryBuilder {
    /**
     * 开闭原则
     * @param in
     * @return
     */
    public static SqlSessionFactory build(InputStream in) throws DocumentException {
        // 1.使用dom4j来解析配置文件sqlMapConfig.xml,并封装到Configuration中
        XMLConfigBuild xmlConfigBuild = new XMLConfigBuild();
        Configuration configuration =  xmlConfigBuild.parseConfig(in);
        // 2.创建sqlSessionFactory对象
        SqlSessionFactory sessionFactory = new DefaultSqlSessionFactory(configuration);

        return sessionFactory;

    }
}
